package main

func lengthOfLongestSubstring2(s string) int {
	max := 0
	for i := 0; i < len(s); i++ {
		m := make(map[byte]byte)
		for j := i; j < len(s); j++ {
			_, ok := m[s[j]]
			if ok {
				break
			}
			m[s[j]] = 1
		}

		if len(m) > max {
			max = len(m)
		}
	}

	return max
}

func lengthOfLongestSubstring(s string) int {
	max := 0
	m := make(map[byte]byte)
	left, right := 0, 0
	for right < len(s) {
		_, ok := m[s[right]]
		if ok {
			for ok {
				delete(m, s[left])
				_, ok = m[s[right]]
				left++
			}
		}

		m[s[right]] = 1

		right++
		if len(m) > max {
			max = len(m)
		}
	}

	return max
}

func main() {
	lengthOfLongestSubstring("pwwkew")
}
